refs: Add argument --list to print the full ref name
authorGiuseppe Scrivano <gscrivan@redhat.com>
Wed, 2 Mar 2016 09:48:52 +0000 (10:48 +0100)
committerColin Walters <walters@verbum.org>
Wed, 2 Mar 2016 19:53:14 +0000 (14:53 -0500)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
man/ostree-refs.xml
src/ostree/ot-builtin-refs.c
tests/test-refs.sh

index 6d75d3651cbc0cd9492c84cc4eb4e266688398f9..43e934ff9c3332731d0de839034c85272651b9e4 100644 (file)
@@ -65,6 +65,16 @@ Boston, MA 02111-1307, USA.
         <title>Options</title>
 
         <variablelist>
+            <varlistentry>
+                <term><option>--list</option></term>
+
+                <listitem><para> For historical reasons, <literal>refs</literal>
+                without this option will strip the specified prefix
+                from the output.  Normally, one wants to see the full
+                ref, so providing this option ensures the refs are
+                printed in full, rather than
+                truncated. </para></listitem>
+            </varlistentry>
             <varlistentry>
                 <term><option>--delete</option></term>
 
index dabb285cd22f6988fe20e4ac926e74a73b12b45a..af90c841e9767ae79654465b716c4720f0cb5df5 100644 (file)
 #include "ostree.h"
 
 static gboolean opt_delete;
+static gboolean opt_list;
 
 static GOptionEntry options[] = {
   { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", NULL },
+  { "list", 0, 0, G_OPTION_ARG_NONE, &opt_list, "Do not remove the prefix from the refs", NULL },
   { NULL }
 };
 
@@ -40,11 +42,17 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
   gpointer hashkey, hashvalue;
   gboolean ret = FALSE;
 
-  if (!opt_delete)
+  if (opt_delete || opt_list)
     {
-      if (!ostree_repo_list_refs (repo, refspec_prefix, &refs, cancellable, error))
+      if (!ostree_repo_list_refs_ext (repo, refspec_prefix, &refs, OSTREE_REPO_LIST_REFS_EXT_NONE,
+                                      cancellable, error))
         goto out;
+    }
+  else if (!ostree_repo_list_refs (repo, refspec_prefix, &refs, cancellable, error))
+    goto out;
 
+  if (!opt_delete)
+    {
       g_hash_table_iter_init (&hashiter, refs);
       while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
         {
@@ -54,10 +62,6 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
     }
   else
     {
-      if (!ostree_repo_list_refs_ext (repo, refspec_prefix, &refs, OSTREE_REPO_LIST_REFS_EXT_NONE,
-                                      cancellable, error))
-        goto out;
-
       g_hash_table_iter_init (&hashiter, refs);
       while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
         {
index b46ec9da7bd6dca9dae81a9cba576694ef42a8c4..bcebae9edffe9e05d4c79161a3a623493c35efd7 100644 (file)
@@ -45,6 +45,9 @@ assert_file_has_content refscount "^10$"
 ${CMD_PREFIX} ostree --repo=repo refs foo > refs
 assert_not_file_has_content refs foo
 
+${CMD_PREFIX} ostree --repo=repo refs --list foo > refs
+assert_file_has_content refs foo
+
 ${CMD_PREFIX} ostree --repo=repo refs foo | wc -l > refscount.foo
 assert_file_has_content refscount.foo "^5$"